//package com.yupi.oj.controller;
//
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.yupi.oj.exception.BusinessException;
//import com.yupi.oj.exception.ThrowUtils;
//import com.yupi.oj.common.BaseResponse;
//import com.yupi.oj.common.ErrorCode;
//import com.yupi.oj.common.ResultUtils;
//import com.yupi.oj.model.dto.post.PostQueryRequest;
//import com.yupi.oj.model.dto.postfavour.PostFavourAddRequest;
//import com.yupi.oj.model.dto.postfavour.PostFavourQueryRequest;
//import com.yupi.oj.model.entity.Post;
//import com.yupi.oj.model.entity.User;
//import com.yupi.oj.model.vo.PostVO;
//import com.yupi.oj.service.PostFavourService;
//import com.yupi.oj.service.PostService;
//import com.yupi.oj.service.UserService;
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
///**
// * 帖子收藏接口
// */
//@RestController
//@RequestMapping("/post_favour")
//@Slf4j
//public class PostFavourController {
//
//    @Resource
//    private PostFavourService postFavourService;
//
//    @Resource
//    private PostService postService;
//
//    @Resource
//    private UserService userService;
//
//    /**
//     * 收藏 / 取消收藏
//     *
//     * @param postFavourAddRequest
//     * @param request
//     * @return resultNum 收藏变化数
//     */
//    @PostMapping("/")
//    public BaseResponse<Integer> doPostFavour(@RequestBody PostFavourAddRequest postFavourAddRequest,
//            HttpServletRequest request) {
//        if (postFavourAddRequest == null || postFavourAddRequest.getPostId() <= 0) {
//            throw new BusinessException(ErrorCode.PARAMS_ERROR);
//        }
//        // 登录才能操作
//        final User loginUser = userService.getLoginUser(request);
//        long postId = postFavourAddRequest.getPostId();
//        int result = postFavourService.doPostFavour(postId, loginUser);
//        return ResultUtils.success(result);
//    }
//
//    /**
//     * 获取我收藏的帖子列表
//     *
//     * @param postQueryRequest
//     * @param request
//     */
//    @PostMapping("/my/list/page")
//    public BaseResponse<Page<PostVO>> listMyFavourPostByPage(@RequestBody PostQueryRequest postQueryRequest,
//            HttpServletRequest request) {
//        if (postQueryRequest == null) {
//            throw new BusinessException(ErrorCode.PARAMS_ERROR);
//        }
//        User loginUser = userService.getLoginUser(request);
//        long current = postQueryRequest.getCurrent();
//        long size = postQueryRequest.getPageSize();
//        // 限制爬虫
//        ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
//        Page<Post> postPage = postFavourService.listFavourPostByPage(new Page<>(current, size),
//                postService.getQueryWrapper(postQueryRequest), loginUser.getId());
//        return ResultUtils.success(postService.getPostVOPage(postPage, request));
//    }
//
//    /**
//     * 获取用户收藏的帖子列表
//     *
//     * @param postFavourQueryRequest
//     * @param request
//     */
//    @PostMapping("/list/page")
//    public BaseResponse<Page<PostVO>> listFavourPostByPage(@RequestBody PostFavourQueryRequest postFavourQueryRequest,
//            HttpServletRequest request) {
//        if (postFavourQueryRequest == null) {
//            throw new BusinessException(ErrorCode.PARAMS_ERROR);
//        }
//        long current = postFavourQueryRequest.getCurrent();
//        long size = postFavourQueryRequest.getPageSize();
//        Long userId = postFavourQueryRequest.getUserId();
//        // 限制爬虫
//        ThrowUtils.throwIf(size > 20 || userId == null, ErrorCode.PARAMS_ERROR);
//        Page<Post> postPage = postFavourService.listFavourPostByPage(new Page<>(current, size),
//                postService.getQueryWrapper(postFavourQueryRequest.getPostQueryRequest()), userId);
//        return ResultUtils.success(postService.getPostVOPage(postPage, request));
//    }
//}
